package cn.demo.cm.service.impl;

import java.time.LocalDateTime;
import java.util.List;

import cn.demo.common.utils.ObjUtils;
import cn.demo.common.utils.SecurityUtils;
import cn.demo.common.utils.StringUtils;
import com.mybatisflex.core.paginate.Page;
import cn.demo.common.core.page.PageQuery;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import cn.demo.cm.mapper.CmFeedbackMapper;
import cn.demo.cm.domain.CmFeedback;
import cn.demo.cm.service.ICmFeedbackService;

/**
 * 反馈信息Service业务层处理
 *
 * @author xtjun
 * @date 2024-06-06
 */
@Service
public class CmFeedbackServiceImpl extends ServiceImpl<CmFeedbackMapper, CmFeedback> implements ICmFeedbackService {
    @Resource
    private CmFeedbackMapper cmFeedbackMapper;
    /**
     * 查询反馈信息
     *
     * @param id 反馈信息主键
     * @return 反馈信息
     */
    @Override
    public CmFeedback selectCmFeedbackById(String id) {
        return cmFeedbackMapper.selectOneById(id);
    }

    /**
     * 查询反馈信息列表
     *
     * @param cmFeedback 反馈信息
     * @return 反馈信息
     */
    @Override
    public Page<CmFeedback> selectCmFeedbackPage(CmFeedback cmFeedback, PageQuery pageQuery) {
        return cmFeedbackMapper.paginate(pageQuery.build(), QueryWrapper.create(cmFeedback,CmFeedback.operators));
    }
    @Override
    public List<CmFeedback> selectCmFeedbackList(CmFeedback cmFeedback) {
        return cmFeedbackMapper.selectListByQuery(QueryWrapper.create(cmFeedback,CmFeedback.operators));
    }

    /**
     * 新增反馈信息
     *
     * @param cmFeedback 反馈信息
     * @return 结果
     */
    @Override
    public int insertCmFeedback(CmFeedback cmFeedback) {
        return cmFeedbackMapper.insert(cmFeedback);
    }

    /**
     * 修改反馈信息
     *
     * @param cmFeedback 反馈信息
     * @return 结果
     */
    @Override
    public int updateCmFeedback(CmFeedback cmFeedback) {
        if (null != cmFeedback.getIsHandle() && cmFeedback.getIsHandle() > 0) {
            if (ObjUtils.isEmpty(cmFeedback.getHandleTime())) cmFeedback.setHandleTime(LocalDateTime.now());
            if (StringUtils.isEmpty(cmFeedback.getHandleUser())) cmFeedback.setHandleUser(SecurityUtils.getUsername());
        }
        return cmFeedbackMapper.update(cmFeedback);
    }

    /**
     * 批量删除反馈信息
     *
     * @param ids 需要删除的反馈信息主键
     * @return 结果
     */
    @Override
    public int deleteCmFeedbackByIds(List<String> ids) {
        return cmFeedbackMapper.deleteBatchByIds(ids);
    }

    /**
     * 删除反馈信息信息
     *
     * @param id 反馈信息主键
     * @return 结果
     */
    @Override
    public int deleteCmFeedbackById(String id) {
        return cmFeedbackMapper.deleteById(id);
    }
}
